#include "includes.h"
#include "sdconfig.h"
#include "ff.h"
FATFS SystemFile;

extern FRESULT scan_files (char* path);
extern void uart_asm_init(void);
extern int32 DisplayLogo(void);

extern int32 Load_NK_nb0(int32 ShowProgress);
extern int32 Load_NK_bin(int32 ShowProgress);
void main(void)
{
	volatile FRESULT  ret_code;
	char CmdBuf[CLI_MAX_CMDLINE_LEN];
	char *ArgVList[CLI_MAX_ARG_COUNT*sizeof(char *)];
	unsigned int ArgCount;
    
	//InItPrintf(putch);
	InitLCD();
    SetPwm(100);
	InItPrintf(LcdDisplay);
	Uart_Init();

	printk("\r\nlboot start.....\r\n");
    printk(" _           ________      ______      ______     _________   \r\n");
	printk("| |          | |____ \\    / ____ \\    / ____ \\   |_________|  \r\n");
	printk("| |          | |    | |  | /    \\ |  | /    \\ |      | |      \r\n");
	printk("| |          | |    | |  | |    | |  | |    | |      | |      \r\n");
	printk("| |          | |___/ /   | |    | |  | |    | |      | |      \r\n");
	printk("| |          | |___| |   | |    | |  | |    | |      | |      \r\n");
	printk("| |          | |   \\ \\   | |    | |  | |    | |      | |      \r\n");
	printk("| |          | |    | |  | |    | |  | |    | |      | |      \r\n");
	printk("| |________  | |____| |  | \\____/ |  | \\____/ |      | |      \r\n");
	printk("|__________| | _______/   \\______/    \\______/       |_|      \r\n");
	//printk("Design: LiuQiang\r\n");
	//printk("Supprt: lq_chongqing@163.com\r\n");

	
    ret_code = f_mount(0,&SystemFile); //  
    if(ret_code==FR_OK){
		printk("File system mount OK\r\n");
        if(GetchTimeout(10000)==OEM_DEBUG_READ_NODATA){
            if(DisplayLogo()==0){
                InItPrintf(putch);	
            }
            Load_NK_bin(1);
        }
    }
	else
		printk("File system mount failure\r\n");
	
		
	
	InItPrintf(putch);
    while(1){
        //
		//	Get command line
		//
		ArgCount = GetCmdLine(CmdBuf, (char**)&ArgVList);
        
		CLIOutputString("\r\n");
		//
		//	Dispatch the Cmd
		//
		if (ArgCount) {
			DispatchCmd(ArgCount, (char**)&ArgVList);
		}   
    }
}

